public class BinarySort {
    private static int binarySort(int[] arr, int target){
        int left = 0;
        int right = arr.length -1;
        while (left <= right){
            int mid = left + (right - left)/2;
            if (arr[mid] == target){
                return mid;
            } else if (arr[mid] < target){
                left = mid +1;
            } else {
                right =mid -1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        // 二分查找的前提是一个有序的array
        int[] arr = {1,4,45,43,90,344};
        int index = binarySort(arr, 45);
    }
}
